﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class KyLuatRepository : GenericRepository<MainDataContainer>
    {
        public KyLuatRepository(string connectionString) : base(connectionString, "MainData") { }
        public KyLuatRepository(MainDataContainer context) : base(context) { }

        public KyLuat GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<KyLuat>(d => d.ID == IDFilter);
            return query;
        }

        public IEnumerable<KyLuat> GetAll()
        {
            var query = this.GetAll<KyLuat>();
            return query;
        }

        public IEnumerable<KyLuat> GetAllBySinhVienID(int SinhVienIDFilter)
        {
            var query = this.GetAll<KyLuat>().Where(d => d.SinhVienID == SinhVienIDFilter);
            return query;
        }

        public void Save(KyLuat obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<KyLuat>(obj);
                }
                else
                {
                    this.Add<KyLuat>(obj);
                }
            }
            catch { }
        }

        public void Remove(KyLuat obj)
        {
            this.Delete<KyLuat>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<KyLuat>(k => k.ID == IDFilter);
            this.Delete<KyLuat>(obj);
        }
    }
}
